#
# Copyright (C) 1988, Shinji Kono 
# Everyone is permitted to copy and distribute verbatim copies
# of this license, but changing it is not allowed.  You can also
# use this wording to make the terms for other programs.
#
# send your comments to kono@mtl.u-tokyo.ac.jp
#
#
# Copyright (C) 1991, Shinji Kono, Sony Computer Science Laboratory, Inc.
#                                  The University, Newcastle upton Tyne
#
# Everyone is permitted to copy and distribute verbatim copies
# of this license, but changing it is not allowed.  You can also
# use this wording to make the terms for other programs.
#
# send your comments to kono@csl.sony.co.jp
#

PROLOG = sicstus
PROLOG_TYPE = SICSTUS

#PROLOG = sbprolog
#PROLOG_TYPE = SBPROLOG

#PROLOG = cprolog
#PROLOG_TYPE = CPROLOG

#PROLOG = xsb
#PROLOG_TYPE = XSB

# PROLOG = prolog
# PROLOG_TYPE = PROLOG

#  SICSTUS 			for SICStus Prolog
#    SICSTUS218                     patch for v2.1 #8
#  SBPROLOG 			for SB Prolog
#  QUINTUS 			for Quintus Prolog
#  CPROLOG 			for CPROLOG ver 1.2
#    CPROLOG15 			for CPROLOG15 ver 1.5
#  see cp.pl.c

all:	$(PROLOG_TYPE)

cp.pl : cppl.c
	cc -E -D$(PROLOG_TYPE) cppl.c | sed -e '/^#/d' > cp.pl

.SUFFIXES: .pl .ql
.SILENT:
OBJ = to.ql tc.ql td.ql te.ql tf.ql tg.ql th.ql \
	tp.ql tr.ql tu.ql xf.ql cp.ql

SICSTUS: cp.pl
	echo '[initm],save(tokio),tokio:r_header. ' | $(PROLOG)
CPROLOG: cp.pl
	echo '[iall],save(tokio),r_header. ' | $(PROLOG)

SB_START_FILE = /usr/local/lib/sbprolog/modlib/\$$readloop 
SBPROLOG: cp.pl 
	echo "['ts.pl']." > .tmpb
	make $(OBJ)
	cat .tmpb | $(PROLOG)
	cat $(SB_START_FILE) $(OBJ) > tokio

XSB: cp.pl
	echo '[iall].' | $(PROLOG)

PROLOG: cp.pl
	echo '[iall].' | $(PROLOG)

WORK = .tmpl .tmpc .tmpa .tmpb

tmpa:
	rm -f $(WORK)
	touch $(WORK)
	make  $(OBJ)
	echo '?-load(['$(OBJ)']).' | \
		sed -e 's/\.ql//g' -e 's/ *$$//' -e 's/ /,/g' > .tmpa

.pl.ql:
	echo '?-fcompile('$*').' >> .tmpc
	echo '?-load('$*').' >> .tmpl
	echo "compile('$<','$@')." >> .tmpb

clean:
	rm -f tokio cp.pl *.ql $(WORK) *.P *.O

pack:
	tar cvf -  read.me \
	`echo $(OBJ) | sed -e 's/\.ql/\.pl/g' ` \
	Makefile initm mall call example.tokio | compress |\
	uuencode Tokio.tar.Z > Tokio.tar.Z.uu

cp.ql : cp.pl

M=tokio:

.PRECIOUS:	tokio

tokio:
	(echo  "[initm], " \
	"gc, save(tokio,B)," \
	"(B=1 -> $(M)r_header,tokio; halt)." )\
	| $(PROLOG)  -f

#
